package com.example.demo.zookeeper.config;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

import java.util.concurrent.CountDownLatch;

import static org.apache.zookeeper.Watcher.Event.KeeperState.SyncConnected;

/**
 * @author liweizhi
 * @date 2020/6/21
 */
public class DefaultWatch implements Watcher {

    private CountDownLatch cdl;

    public DefaultWatch(CountDownLatch cdl) {
        this.cdl = cdl;
    }

    @Override
    public void process(WatchedEvent event) {
        System.out.println("DefaultWatch:" + event.toString());
        if (event.getState().equals(SyncConnected)) {
            cdl.countDown();
        }
    }
}
